package com.beiju.coupon;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@MapperScan("com.beiju.coupon.mapper")
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class CouponApplication {

  public static void main(String[] args) {
    SpringApplication.run(CouponApplication.class, args);
  }

  /**
   * 配置swagger2文档
   * UI地址为：IP：端口/doc.html
   * @return
   */
  @Bean
  public Docket createRestApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            //声明那些文件需要接口注释
            .apis(RequestHandlerSelectors.basePackage("com.beiju.coupon.controller"))
            .paths(PathSelectors.any())
            .build();
  }

  private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
            //标题
            .title("来领券咯接口文档")
            //描述
            .description("没有什么可以描述的")
            //这里配置的是服务网站
            .termsOfServiceUrl("http://www.baidu.com")
            //作者信息
            .contact(new Contact("陈浩","http://www.baidu.com","1094732594@qq.com"))
            .version("1.0")
            .build();
  }
}
